<template >
  <div class="add_con_form tl" v-loading="loading">
    <el-dialog :close-on-click-modal="false" title="更换群主" :modal-append-to-body="false" :visible.sync="visible" :show="show"
        :before-close="closeDialog" @close="$emit('update:show',false)" class="tl size_13" width="800px">
      <el-form :model="data" :rules="dataYZ" ref="data" class="mar_top" label-width="120px">
        <el-form-item label="群主账号" prop="username">
          <el-col :span="12">
            <el-input placeholder="请输入群主账号" v-model="data.username" clearable></el-input>
          </el-col>
        </el-form-item>

        <div class="mar_bottom_15">
          <span class="sizeColor size_13 sp_style"></span>
          <el-button :loading="$store.state.isLoading" size="medium" type="primary" @click.prevent="addUpdate('data')">确定</el-button>
        </div>
      </el-form>
    </el-dialog>
  </div>
</template>


<style lang="less" scoped></style>

<script>
export default {
  data () {
    var checkTitle = (rule, value, callback) => {
      if (!value) {
        return callback(new Error("账号不能为空"));
      } else {
        callback();
      }
    };

    return {
      value: "",
      data: {
        id: "",
        boss_uid: "",
        username: ""
      },
      loading: false,
      dataYZ: {
        username: [{ validator: checkTitle, trigger: "blur" }]
      },
      visible: this.show
    };
  },
  props: {
    show: Boolean,
    rechargeId: String
  },
  methods: {
    closeDialog () {
      //this.$refs['data'].resetFields();
      this.visible = false;
    },
    getDetails (id) {
      var data = {};
      data["id"] = id;
      this.$api.getIMteam.getImTeamInfo(data).then(res => {
        this.data = res.data.result;
      });
    },
    addUpdate (formName) {
      this.$refs[formName].validate(valid => {
        if (valid) {
          var params = {};
          params["id"] = this.data.id;
          params["username"] = this.data.username;

          this.$api.getIMteam.ImTeamUpdate(params).then(res => {
            console.log(res);
            if (res.data.code == 200 && res.data.result != null) {
              this.$emit("parent", "这里刷新父页面");
              this.$fnc.alertSuccess({ text: "编辑成功" }); //成功弹出框
              this.visible = false;
            } else {
              this.$fnc.alertError(res.data.result); //失败弹出框
            }
          });
        }
      });
    }
  },
  watch: {
    show () {
      console.log(this.show);
      this.visible = this.show;
    },
    rechargeId (id) {
      console.log("id", id);
      this.getDetails(id);
    }
  },
  mounted () {
    //this.getDetails(this.$route.query.id);
  },
  created () { }
};
</script>
